<!-- spu明细 -->
<template>
  <div class="clas_All">
    <el-table :data="tableDataTow">
      <el-table-column align="center" label="序号" type="index" width="50">
      </el-table-column>
      <el-table-column align="center" prop="dname" label="部门">
      </el-table-column>
      <el-table-column align="center" prop="" label="性质"> </el-table-column>
      <el-table-column align="center" prop="pname" label="物料名称">
      </el-table-column>
      <el-table-column align="center" prop="unitName" label="库存单位">
      </el-table-column>
      <el-table-column align="center" prop="price" label="单价">
      </el-table-column>
      <el-table-column align="center" prop="stapName" label="价格属性">
      </el-table-column>
      <el-table-column align="center" prop="inNum" label="实际耗用数量(库)">
      </el-table-column>
      <el-table-column align="center" prop="realCostUpper" label="实际耗用成本">
      </el-table-column>
      <el-table-column align="center" prop="outNum" label="核算用量数量(库)">
      </el-table-column>
      <el-table-column
        align="center"
        prop="standardCostUpper"
        label="核算耗用成本"
      >
      </el-table-column>
      <el-table-column align="center" prop="prolossNum" label="损益数量(库)">
      </el-table-column>
      <el-table-column align="center" prop="prolossAmout" label="损益金额">
      </el-table-column>
      <!-- <el-table-column
        align="center"
        prop="stapName"
        label="损益比上期数量差(库)"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="stapName"
        label="损益比上期价格差(库)"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="stapName"
        label="损益比上期金额差(库)"
      >
      </el-table-column> -->
      <el-table-column label="操作" props="" align="center">
        <template slot-scope="scope">
          <div>
            <el-button size="mini" type="text" @click="GoDEPT"
              >该部门该物料sku盘点及核算表</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="该部门该物料sku盘点及核算表"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div style="margin: 8px">
        <el-table :data="tableDataOne" style="width: 100%">
          <el-table-column>
            <el-table-column prop="data" align="center" label="用途">
            </el-table-column>
            <el-table-column align="center" label="库存单位（单位）">
              <el-table-column prop="num" align="center" label="数量">
              </el-table-column>
              <el-table-column prop="price" align="center" label="均价">
              </el-table-column>
            </el-table-column>
            <el-table-column prop="amout" align="center" label="金额">
            </el-table-column>
            <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <div v-if="scope.row.show">
                  <el-button size="mini" type="text" @click="GoOpen(scope.row)">
                    {{ scope.row.data }}
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
        <el-button @click="dialogVisible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  stapprolossInfo,
  Infostapproloss,
  originalStapProlossStapDetail,
} from "@/api/system/cost";
export default {
  props: {
    dataOne: {
      type: Array,
    },
  },
  data() {
    return {
      queryParams: {},
      examineOption: [],
      dialogVisible: false,
      tableDataTow: [],
      tableDataOne: [
        {
          data: "期初(+)",
        },
        {
          data: "采购(+)",
        },
        {
          data: "调入(+)",
        },
        {
          data: "调出(-)",
        },
        {
          data: "期末(-)",
        },
        {
          data: "实际",
          show: true,
        },
        {
          data: "核算",
          show: true,
        },
      ],
    };
  },
  created() {
    this.queryParams.shopCode = this.$route.query.shopCode;
    this.queryParams.pandianCode = this.$route.query.pandianCode;
    this.queryParams.deptCode = this.$route.query.deptCode;
    this.queryParams.stapCode = this.$route.query.stapCode;

    // console.log(this.queryParams);
    // this.getList();
    this.getListOne();
  },
  methods: {
    handleQuery() {},
    getList() {
      this.tableDataOne.forEach((item, index) => {
        item.type = index + 1;
      });
      stapprolossInfo(this.queryParams).then((res) => {
        if (res.code == 200) {
          // this.tableData = res.data;
          // res.data.forEach((ite) => {
          //   this.tableDataOne[ite.type - 1] = {
          //     ...this.tableDataOne[ite.type - 1],
          //     ...ite,
          //   };
          // });
          this.tableDataOne.forEach((item, index) => {
            switch (item.type) {
              case 1:
                // 期初
                item.num = res.data.lastPandianNum;
                item.price = res.data.lastPandianPrice;
                item.amout = res.data.lastPandianAmount;
                break;
              case 2:
                // 采购
                item.num = res.data.incaseNum;
                item.price = res.data.incasePrice;
                item.amout = res.data.incaseAmount;
                break;
              case 3:
                // 调入
                item.num = res.data.transferInNum;
                item.price = res.data.transferPrice;
                item.amout = res.data.transferInAmount;
                break;
              case 4:
                // 调出
                item.num = res.data.transferOutNum;
                item.price = res.data.transferPrice;
                item.amout = res.data.transferOutAmount;
                break;
              case 5:
                // 期末
                item.num = res.data.thisPandianNum;
                item.price = res.data.thisPandianPrice;
                item.amout = res.data.thisPandianAmount;
                break;
              case 6:
                // 实际
                item.num =
                  res.data.lastPandianNum +
                  res.data.incaseNum +
                  res.data.transferInNum -
                  res.data.transferOutNum -
                  res.data.thisPandianNum;
                // item.price = res.data
                item.amout =
                  res.data.lastPandianAmount +
                  res.data.incaseAmount +
                  res.data.transferInAmount -
                  res.data.transferOutAmount -
                  res.data.thisPandianAmount;
                item.pandianCode = res.data.pandianCode;
                item.stapCode = res.data.stapCode;
                item.deptCode = res.data.deptCode;
                break;
              case 7:
                // 核算
                item.num = res.data.outStapNum;
                // item.price= res.data.
                item.amout = res.data.outStapAmount;
                item.pandianCode = res.data.pandianCode;
                item.stapCode = res.data.stapCode;
                item.deptCode = res.data.deptCode;
                break;
              default:
                break;
            }
          });
          // console.log(this.tableDataOne);
          this.$forceUpdate();
          this.dialogVisible = true;
        }
      });
    },
    getListOne() {
      Infostapproloss(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.tableDataTow = res.data;
        }
      });
    },
    GoDEPT() {
      // this.$router.push("/");
      this.getList();
      // dialogVisible = false
    },
    handleClose() {},
    GoOpen(v) {
      // console.log(v);
      if (v.type == 6) {
        this.$router.push({
          path: "/detaolone",
          query: {
            pandianCode: this.queryParams.pandianCode,
            stapCode: this.queryParams.stapCode,
            deptCode: this.queryParams.deptCode,
          },
        });
      } else if (v.type == 7) {
        this.$router.push({
          path: "/detaoltwo",
          query: {
            pandianCode: this.queryParams.pandianCode,
            stapCode: this.queryParams.stapCode,
            deptCode: this.queryParams.deptCode,
          },
        });
      }
    },
  },
  mounted() {
    // this.$router.push("/");
  },
};
</script>

<style lang="scss" scoped>
.clas_All {
  margin: 20px;
}
</style>
